package com.zzz.algorithm;

public class Bf {


    public int indexOf(String source, String target) {
        if (target.length() > source.length()) return -1;
        out:
        for (int i = 0; i < source.length();) {
            while (source.charAt(i) != target.charAt(0)) {
                if (i + target.length() > source.length())
                    return -1;
                i++;
            }

            int j = i + 1;
            for (int k = 0; k < target.length() - 1; k++) {
                char s = source.charAt(j + k);
                char t = target.charAt(k + 1);
                if (s != t) {
                    i++;
                    continue out;
                }
            }
            return i;

        }
        return -1;
    }

    public void test(String source, String target, int count) {
        //[-1, -1, 0, 1, -1, 0, 0, 1, 2]
        //[-1, 0, -1, 1, 0, 2, -1, 0, -1]
        for (int i = 0; i < count; i++) {
            indexOf(source, target);
        }
    }

}
